#ifndef __TcpSocket_h__
#define __TcpSocket_h__

#include <base/types.h>
#include "IpSocket.h"

#include <string>

using namespace Greatewall::Interface;

namespace Greatewall
{
    namespace Network
    {
        class TcpSocket : public IpSocket
        {
        public:
            enum TcpMode
            {
                CLIENT,
                CLIENT_HANDLER,
                SERVER
            };

            TcpSocket(SocketEventMonitor& monitor, SysSockHandler hdl = -1) 
                : IpSocket(monitor, hdl)
            {}

            virtual ~TcpSocket()
            {}

            virtual void
            handleInbound() = 0;

            virtual bool
            handleOutbound() = 0;

            virtual bool
            send(const char* buf, ssize_t& size, bool non_block = true);

            virtual bool
            recv(char*& buf, ssize_t& size, bool non_block = true);

            static SysSockHandler
            createTcpSock();

            bool
            initTcpSock(std::string host, short port, std::string netif);

            bool
            initTcpSock(short port, int backlog, std::string& netif);

            bool
            initTcpSock(SysSockHandler hdl, std::string host, int port);

            virtual void
            close();

        private:
            std::string _host;
            short       _port;
            std::string _netif;
            TcpMode     _mode;
        };
    }
}
#endif
